package cn.yunhe.video.controller;


import cn.yunhe.video.Service.ICollectService;
import cn.yunhe.video.entity.Collect;
import cn.yunhe.video.entity.UserInfo;
import cn.yunhe.video.entity.Video;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CollectController {

    @Autowired
    private ICollectService collectService;


    /**
     * 收藏
     *
     * @param request
     */
    @RequestMapping("/addCollect")
    @ResponseBody
    public void addCollect(HttpServletRequest request){
        int videoId=Integer.parseInt(request.getParameter("video"));
        int uid=Integer.parseInt(request.getParameter("uid"));
        Video video = new Video();
        video.setId(videoId);
        UserInfo userInfo = new UserInfo();
        userInfo.setUid(uid);
        Collect collect = new Collect(video,userInfo);
        collectService.addCollect(collect);
        collectService.updateCollectUp(collect);
    }


    /**
     * 取消收藏
     *
     * @param request
     */
    @RequestMapping("/delCollect")
    @ResponseBody
    public void delCollect(HttpServletRequest request){
        int uid=Integer.parseInt(request.getParameter("uid"));
        int videoId=Integer.parseInt(request.getParameter("video"));
        Video video = new Video();
        video.setId(videoId);

        UserInfo userInfo = new UserInfo();
        userInfo.setUid(uid);
        Collect collect = new Collect(video,userInfo);
        collectService.delCollect(collect);
        collectService.updateCollectDown(collect);
    }

}
